<template>
  <div class="diamond">
    <div class="header">
      <span><ChartPie fill="#3590f0" /> 用户占比</span>
    </div>
    <div class="p-20">
      <div class="tips">
        <div v-for="item in fills" :class="item.class">
          <span class="span" :style="{ backgroundColor: item.color }">{{ item.proportion + '%' }}</span>
          <span>{{ item.label }}</span>
        </div>
      </div>
      <div class="charts mt-20">
        <template v-for="item in fills">
          <span v-for="_ in item.proportion" :class="item.class" :style="{ backgroundColor: item.color }"></span>
        </template>
        <span v-for="_ in diffSpans" class="default"></span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ChartPie } from '@icon-park/vue-next';
import { computed } from 'vue';

const fills = [
  {
    label: '小黑子',
    proportion: 62,
    color: '#5cdbd3',
    class: 'black'
  },
  {
    label: '真爱粉',
    proportion: 15,
    color: '#fe97b5',
    class: 'pink'
  },
  {
    label: '纯路人',
    proportion: 8,
    color: '#a97c50',
    class: 'other'
  }
];

const diffSpans = computed(() => {
  return 100 - fills.reduce((sum, acc) => (sum += acc.proportion), 0);
});
</script>

<style scoped lang="scss">
.header {
  width: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  border-bottom: 1px solid var(--admin-border-color);
  font-size: 14px;
}
.tips {
  display: flex;
  gap: 20px;
  > div {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: var(--el-text-color-light6);
    .span {
      margin-right: 4px;
      border-radius: 4px;
      width: 30px;
      height: 30px;
      box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15);
      line-height: 30px;
      text-align: center;
      color: #ffffff;
    }
  }
}

.charts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  > span {
    border-radius: 4px;
    width: 20px;
    height: 20px;
    box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15);
    transition: all 240ms ease-in-out 500ms;
  }

  .default {
    box-shadow: none;
    border: 1px dashed #999;
  }
}

.charts:has(.black:hover) .black,
.charts:has(.pink:hover) .pink,
.charts:has(.other:hover) .other {
  box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.35);
  transition: all 240ms ease-in-out;
}
</style>
